<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/6/30
 * Time: 13:54
 */

namespace ElementVip\JwOms\Handler;

use ElementVip\JwOms\Services\RefundService;

class RefundHandle extends AbstractOms
{
    protected $refundService;

    public function __construct(RefundService $refundService)
    {
        $this->refundService = $refundService;
    }

    public function handle()
    {        
        //上传订单取消数据
        \Log::info('进入上传订单取消数据');
        $data = $this->refundService->getCancelOrderRefundData();
        if ($data['data']) {
            $this->createFile('OrderCancel', 'oc', $data); //仅退款
        }

        //上传退货数据
        \Log::info('进入上传退货数据');
        $refundData = $this->refundService->getRefundData();
        if ($refundData['data']) {
            $this->createFile('OrderReturn', 'sh', $refundData);  //退货退款
        }

        //同步退货数据
        if (count($file = $this->downloadFiles('OrderReturnShip')) > 0) {
            foreach ($file as $item) {
                $this->refundService->syncRefund($item);
            }
        }
    }
}